import qdarkstyle
from PyQt5.QtWidgets import QMessageBox

from src.user.UserBorrowSeclect_UI import Ui_Form
from src.user.UserBorrow_win import UserBorrow_Win
from PyQt5 import QtWidgets
import mysql.connector


class UserBorrowSelect_Win(QtWidgets.QMainWindow,Ui_Form):
    def __init__(self, mydb,parent=None):
        super(UserBorrowSelect_Win, self).__init__(parent=parent)
        #ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('')
        self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
        #self.setWindowIcon(icon)
        self.setupUi(self)
        self.LoginSignal=False
        self.mydb=mydb

        self.UserBorrow_form =UserBorrow_Win(self.mydb)
        self.UserBorrow_form.setWindowTitle("玩具租赁信息界面")

    def myBorrow(self):
        s = self.lineEdit.text()
        s=str(s)
        myselect = "SELECT * FROM single_kind WHERE single_kind.`玩具编号`= "+s
        try:
            mycursor = self.mydb.cursor()
            mycursor.execute(myselect)
        except Exception as a:
            QMessageBox.critical(self, '错误', '信息不正确')
        else:
            result = mycursor.fetchall()
            if len(result) == 0:
                QMessageBox.critical(self, '错误', '请输入正确的玩具编号')
            else:
                self.UserBorrow_form.label_11.setText(result[0][1])
                self.UserBorrow_form.label_13.setText(result[0][2])
                self.UserBorrow_form.label_6.setText(str(result[0][4]))
                self.UserBorrow_form.label_7.setText(result[0][3])
                self.UserBorrow_form.label_10.setText(str(result[0][5]))
                self.UserBorrow_form.show()

    def getMydb(self,mydb):
        self.mydb=mydb

